<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>统一认证中心</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="resources/bootstrap/3.3.7/css/bootstrap.min.css">

<script type="text/javascript" src="resources/js/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="resources/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="resources/layer/layer.js"></script>
<!-- HTML5 Shim 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
<!-- 注意： 如果通过 file://  引入 Respond.js 文件，则该文件无法起效果，必须放置到web服务器中，暂时不必掌握 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->



<script type="text/javascript">
	$(document).ready(function() {
		var url=GetQueryString("callbackURL");
		$("#callbackURL").val(url==null?"":url);
		console.log(url==null?"":url);
		$("#loginSubmit").click(function() {
			var username = $("#username").val();
			var password = $("#password").val();
			var callbackURL = $("#callbackURL").val();
			if(username==null || username==""){
				return false;
			}
			if(password==null || password==""){
				return false;
			}

			if (username != null && password != null) {
				$.ajax({
					type : "POST",
					url : "sso/login",
					data : {"username":username,"password":password,"callbackURL":callbackURL},
					async:true,    //或false,是否异步
					timeout : 60000, //超时时间
					dataType : "json", //返回的数据格式：json/xml/html/script/jsonp/text
					beforeSend : function(xhr) {
						console.log(xhr);
						console.log('发送前');
					},
					success:function(data,textStatus,jqXHR){
				        console.log(data.resultCode+","+data.resultMsg);
				        if(data.resultCode="000000"){
				        	if(data.resultObj.callbackURL==null || data.resultObj.callbackURL==""){
				        		window.document.location.href="index.html";
				        	}else{
				        		window.document.location.href=data.resultObj.callbackURL;
				        	}
				        }else{
				        	alert(data.resultCode+","+data.resultMsg);
				        }
				        console.log(textStatus);
				        console.log(jqXHR);
				    },
					error : function(xhr, textStatus) {
						console.log('错误');
						console.log(xhr);
						console.log(textStatus);
					},
					complete : function() {
						console.log('结束');
					}
				});
				return true;
			}
		});
	});

	function GetQueryString(name){
	     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	     var r = window.location.search.substr(1).match(reg);
	     if(r!=null)return  unescape(r[2]); return null;
	}

</script>
</head>
<body>
<!-- 	<div class="container">
		<form id ="loginForm" class="form-signin" role="form">
			<h2 class="form-signin-heading">用户登录</h2>
			<input type="text" id="username" name="username" class="form-control"
				placeholder="请输入用户名" required>
			<div style="height: 10px; clear: both; display: block"></div>
			<input type="password" id="password" name="password"
				class="form-control" placeholder="请输入密码" required>
			<div class="checkbox">
				<label> <input type="checkbox" value="remember-me">
					记住登录状态
				</label>
			</div>
			<button id="loginSubmit" class="btn btn-lg btn-primary btn-block">登录</button>
		</form>
	</div> -->
	<!--使用模态框的方式模拟一个登陆框-->
    <div class="modal show" id="loginModal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close">&times;</button>
                    <h1 class="text-center text-primary">登录</h1>
                </div>
                <div class="modal-body">
                    <form class="form col-md-12 center-block" id="loginForm">
                    	<input type="hidden" id ="callbackURL" name ="callbackURL" value="">
                        <div class="form-group-lg"  id="accountDiv">
                            <label class="sr-only" for="inputAccount">账号</label>
                            <div class="input-group">
                                <div class="input-group-addon"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></div>
                                <input class="form-control" id="username" name="username" type="text" placeholder="账号" required autofocus>
                            </div>
                            <div class="hidden text-center" id="accountMsg"><span class="glyphicon glyphicon-exclamation-sign"></span>用户名不存在</div>
                        </div>
                        <br>
                        <div class="form-group-lg" id="pwdDiv">
                            <label class="sr-only" for="inputPassword">密码</label>
                            <div class="input-group">
                                <div class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></div>
                                <input class="form-control" id="password" name="password" type="password" placeholder="密码" required>
                                <div class="input-group-addon"><span class="glyphicon glyphicon-eye-open"></span></div>
                            </div>
                            <div class="hidden text-center" id="pwdMsg"><span class="glyphicon glyphicon-exclamation-sign"></span>用户名密码错误</div>
                        </div>
                        <div class="checkbox">
                            <label> <input type="checkbox" value="remember-me">记住我</label>
                        </div>
                        <div class="form-group">
                        	<button class="btn btn-primary btn-lg col-md-5" id="loginSubmit" type="button" >登录</button>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <button class="btn btn-default btn-lg col-md-5" id="btn_register" type="button">注册</button>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">

                </div>
            </div>
        </div>
    </div>
</body>
</html>
